package site.qjdb.pojo;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Date;

/**
 * 	购物车
 * 
 * */
public class Cart {
	private Integer cartId; // 购物车id
	private Integer uid; // 用户id
	private Goods goods; // 购物车内的商品
	private Integer count; // 购买数量
	private String realSubtotal; // 购物车项小计，真实小计
	private Integer dbSubtotal; // 数据库中存储的价钱
	private Integer isDel; // 是否删除，0：没有删除，1：已删除
	private Date time; // 添加进购物车的时间
	
	public Cart() {}

	public Integer getCartId() {
		return cartId;
	}

	public void setCartId(Integer cartId) {
		this.cartId = cartId;
	}

	public Integer getUid() {
		return uid;
	}

	public void setUid(Integer uid) {
		this.uid = uid;
	}

	public Goods getGoods() {
		return goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public String getRealSubtotal() {
		if (this.realSubtotal == null && this.dbSubtotal != null) {
			// 从数据库获取Integer类型数据，转成String类型。目的：用于前端显示
			Double _realSubtotal = this.dbSubtotal / 100d;
			// 0.00表示保留后两位，它的处理方式是直接截掉不要的尾数，不四舍五入。
			DecimalFormat df = new DecimalFormat("0.00");
			this.realSubtotal = df.format(_realSubtotal);
		}
		return realSubtotal;
	}

	public void setRealSubtotal(String realSubtotal) {
		this.realSubtotal = realSubtotal;
	}

	public Integer getDbSubtotal() {
		if (this.dbSubtotal == null && this.realSubtotal != null) {
			// 从web端获取String类型数据，转成Integer类型。目的：1.存储到数据库 2.进行运算
			BigDecimal bigDecimal = new BigDecimal(realSubtotal);
			Double _realSubtotal = bigDecimal.setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
			Double price = _realSubtotal * 100;
			this.dbSubtotal = price.intValue();
		}
		return dbSubtotal;
	}

	public void setDbSubtotal(Integer dbSubtotal) {
		this.dbSubtotal = dbSubtotal;
	}

	public Integer getIsDel() {
		return isDel;
	}

	public void setIsDel(Integer isDel) {
		this.isDel = isDel;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	@Override
	public String toString() {
		return "Cart [cartId=" + cartId + ", uid=" + uid + ", goods=" + goods + ", count=" + count + ", realSubtotal="
				+ realSubtotal + ", dbSubtotal=" + dbSubtotal + ", isDel=" + isDel + ", time=" + time + "]";
	}

}
